<?php
/** AuthenticateController class file.
 * ----------------------------------
 *
 * LICENSE: BSD
 * @copyright  2009 Gemisoft
 * @author Deepak Pradhan <deepak.pradhan@gemisoft.com>
 * @link http://grbac.gemisoft.com/
 * @version $Id$
 * @since 0.1
 */

class AuthenticateController extends BaseController {
/**
 * User authentication actions
 * 1. login
 * 2. logout
 **/

/**
 * Displays the login page and authenticate
 * @param $username string
 * @param $pasword  string
 */
  /*public function actionLogin() {
    $user=new Users('login');

    if(isset($_POST['Users'])) {
      print_r($_POST['Users']);
      $user->attributes=$_POST['Users'];
      //$user->setAttributes($_POST['Users']);
      echo "\nUsername isAA:".print_r($user->username);
      // validates and authenticates
      //if($user->validate('Users'))
      //  $this->redirect(Yii::app()->user->returnUrl);
      
      
       
    }
    $this->render('login',array('form'=>$user));
  }*/
     public function actionLogin() {
    $model=new Users('login');
    // add the scenario
    $model->scenario='login';

    if(isset($_POST['Users'])) {
      $model->setAttributes($_POST['Users']);
      // validates and authenticates
      if($model->validate()) // notice
        $this->redirect(Yii::app()->createUrl('/site/panel'));
        //$this->redirect(Yii::app()->user->returnUrl);

    }
    $this->render('login',array('model'=>$model));
  }

  /**
   * Logout the current user and redirect to homepage.
   */
  public function actionLogout() {
    Yii::app()->user->logout();
    $this->redirect(Yii::app()->homeUrl);
  }


}
